<template>
   <table>
    <tr>
        <td>标题</td>
        <td>
            <input type="text" v-model="showinfo.Name">
        </td>
    </tr>
    <tr>
        <td>券类型</td>
        <td>
           <select v-model="showinfo.QuanType">
                <option :value="0">请选择</option>
                <option :value="1">代金券</option>
                <option :value="2">优惠券</option>
                <option :value="3">折扣券</option>
           </select>
        </td>
    </tr>
    <tr>
        <td>副标题</td>
        <td>
            <input type="text" v-model="showinfo.FName">
        </td>
    </tr>
    <tr>
        <td>图片</td>
        <td>
            <img :src="showinfo.Disimg" style="width: 50px;height: 50px;">
            <input type="file">
        </td>
    </tr>
    <tr>
        <td>剩余库存</td>
        <td>
            <input type="text" v-model="showinfo.Num">
        </td>
    </tr>
    <tr>
        <td>每人限领</td>
        <td>
            <input type="text" v-model="showinfo.Stop">
        </td>
    </tr>
    <tr>
        <td>使用条件</td>
        <td>
            <input type="text" v-model="showinfo.Sytiaojian">
        </td>
    </tr>
    <tr>
        <td>减免金额</td>
        <td>
            <input type="text" v-model="showinfo.JianMian">
        </td>
    </tr>
    <tr>
        <td>有效期</td>
        <td>
            <input type="text" v-model="showinfo.YouXTime">
        </td>
    </tr>
    <tr>
        <td>适用业务</td>
        <td>
            <input type="text" v-model="showinfo.SyYewu">
        </td>
    </tr>
    <tr>
        <td>适用须知</td>
        <td>
            <input type="text" v-model="showinfo.SyXuzhi">
        </td>
    </tr>
    <tr>
        <td>客服电话</td>
        <td>
            <input type="text" v-model="showinfo.Phone">
        </td>
    </tr>
    <tr>
        <td>适用门店</td>
        <td>
<select >
    <option :value="0">请选择</option>
    <option  v-for="i in xlinfo" :value="i.Id">{{ i.S_Name }}</option>
</select>
        </td>
    </tr>
    <tr>
        <td></td>
        <td>
            <input type="button" value="修改" @click="save">
        </td>
    </tr>
   </table>
</template>

<script setup lang="ts">
import { onMounted,ref } from 'vue';
import { useRoute,useRouter } from 'vue-router';
import axios from 'axios'

const  use=useRoute();
const  user=useRouter();

const showinfo=ref({
"Id": 1,
"Name": "",
"QuanType": "",
"FName": "",
"Disimg": "",
"Num": "",
"Stop": "",
"Sytiaojian": "",
"JianMian": "",
"YouXTime": "",
"SyYewu": "",
"SyXuzhi": "",
"Phone": "",
"S_id": 1,
"Shop": null,
"IsDel": true
})
onMounted(()=>{
    xiala()
    fantian()
})

const fantian=()=>{
    axios.get("https://localhost:7238/api/Dis/GetDisByid",{
        params:{
            id:use.params.id
        }
      
    }).then(res=>{
        showinfo.value=res.data
    })
}
const tupian=(e:any)=>{
    var file=e.targer.files[0];
    var fy=new FormData();
    fy.append("Img",file);
    axios.post("").then(res=>{
        showinfo.value.Disimg=res.data
    })


}
const xlinfo=ref({
    "Id": 1,
    "S_Name": "河北石家庄"
})
const xiala=()=>{
axios.get("https://localhost:7238/api/Dis/Getall")
.then(res=>{
xlinfo.value=res.data
})

}
const save=()=>{
    if(showinfo.value.Name==""){
        alert("标题不能为空");
        return;
    }
 
    if(showinfo.value.Phone==""){
        alert("客服电话不能为空");
        return;
    }
    if(showinfo.value.Num==""){
        alert("库存不能为空");
        return;
    }

    axios.put("https://localhost:7238/api/Dis/UpdaDis",showinfo.value)
    .then(res=>{
        if(res.data>0){
            alert("修改成功");
            user.push("/ShowDiscount")
        }else{
            alert("修改失败")
        }
    })
}
</script>

<style scoped>

</style>